var TANGER_OCX_bDocOpen = false;
var TANGER_OCX_filename;
var TANGER_OCX_actionURL; //For auto generate form fiields
var TANGER_OCX_OBJ; //The Control

//??????V1.7????????????

//????????????????????????????
function AddPictureFromLocal()
{
	if(TANGER_OCX_bDocOpen)
	{	
    TANGER_OCX_OBJ.AddPicFromLocal(
	"", //????
	true,//????????????????
	true,//????????????
	100,//????????????????????????????Left ??????
	100); //??????????????????????????????Top
	};	
}

//??URL??????????????????????
function AddPictureFromURL(URL)
{
	if(TANGER_OCX_bDocOpen)
	{
    TANGER_OCX_OBJ.AddPicFromURL(
	URL,//URL ??????URL????????Word????????????????
	true,//????????????
	150,//????????????????????????????Left ??????
	150);//??????????????????????????????Top
	};
}

//??????????????????????????
function AddSignFromLocal()
{

   if(TANGER_OCX_bDocOpen)
   {
      TANGER_OCX_OBJ.AddSignFromLocal(
	"????????",//????????????
	"",//????????
	true,//????????
	0,//left
	0)  //top
   }
}

//??URL????????????????????
function AddSignFromURL(URL)
{
   if(TANGER_OCX_bDocOpen)
   {
      TANGER_OCX_OBJ.AddSignFromURL(
	"????????",//????????????
	URL,//URL
	50,//left
	50)  //top
   }
}

//????????????
function DoHandSign()
{
   if(TANGER_OCX_bDocOpen)
   {	
	TANGER_OCX_OBJ.DoHandSign(
	"????????",//???????????? ????
	0,//????0?????? 0??4 //????????
	0x000000ff, //???? 0x00RRGGBB//????????
	2,//????//????????
	100,//left//????????
	50); //top//????????
	}
}
//????????????????????????????
function DoHandDraw()
{
	if(TANGER_OCX_bDocOpen)
	{	
	TANGER_OCX_OBJ.DoHandDraw(
	0,//????0?????? 0??4 //????????
	0x00ff0000,//???? 0x00RRGGBB//????????
	3,//????//????????
	200,//left//????????
	50);//top//????????
	}
}
//????????????
function DoCheckSign()
{
	if(TANGER_OCX_bDocOpen)
	{		
	var ret = TANGER_OCX_OBJ.DoCheckSign
	(
	/*???????? IsSilent ??????FAlSE????????????????????,??????????????????????????????*/
	);//??????????????????????
	//alert(ret);
	}	
}
//??????????????????????????????????
function TANGER_OCX_AddDocHeader( strHeader )
{
	var i,cNum = 30;
	var lineStr = "";
	try
	{
		for(i=0;i<cNum;i++) lineStr += "_";  //??????????
		with(TANGER_OCX_OBJ.ActiveDocument.Application)
		{
			Selection.HomeKey(6,0); // go home
			Selection.TypeText(strHeader);
			Selection.TypeParagraph(); 	//????
			Selection.TypeText(lineStr);  //??????????
			// Selection.InsertSymbol(95,"",true); //??????????
			Selection.TypeText("??");
			Selection.TypeText(lineStr);  //??????????
			Selection.TypeParagraph();
			//Selection.MoveUp(5, 2, 1); //????????????????Shift??????????????????
			Selection.HomeKey(6,1);  //??????????????????????
			Selection.ParagraphFormat.Alignment = 1; //????????
			with(Selection.Font)
			{
				NameFarEast = "????";
				Name = "????";
				Size = 12;
				Bold = false;
				Italic = false;
				Underline = 0;
				UnderlineColor = 0;
				StrikeThrough = false;
				DoubleStrikeThrough = false;
				Outline = false;
				Emboss = false;
				Shadow = false;
				Hidden = false;
				SmallCaps = false;
				AllCaps = false;
				Color = 255;
				Engrave = false;
				Superscript = false;
				Subscript = false;
				Spacing = 0;
				Scaling = 100;
				Position = 0;
				Kerning = 0;
				Animation = 0;
				DisableCharacterSpaceGrid = false;
				EmphasisMark = 0;
			}
			Selection.MoveDown(5, 3, 0); //????3??
		}
	}
	catch(err){
		//alert("??????" + err.number + ":" + err.description);
	}
	finally{
	}
}
function strtrim(value)
{
	return value.replace(/^\s+/,'').replace(/\s+$/,'');
}

function TANGER_OCX_doFormOnSubmit()
{
	var form = document.forms[0];
  	if (form.onsubmit)
	{
    	var retVal = form.onsubmit();
     	if (typeof retVal == "boolean" && retVal == false)
       	return false;
	}
	return true;
}

//??????????????????????????????????????????????
function TANGER_OCX_EnableReviewBar(boolvalue)
{
	TANGER_OCX_OBJ.ActiveDocument.CommandBars("Reviewing").Enabled = boolvalue;
	TANGER_OCX_OBJ.ActiveDocument.CommandBars("Track Changes").Enabled = boolvalue;
	TANGER_OCX_OBJ.IsShowToolMenu = boolvalue;	//??????????????????
}

//????????????????????
function TANGER_OCX_SetReviewMode(boolvalue)
{
	TANGER_OCX_OBJ.ActiveDocument.TrackRevisions = boolvalue;
}

//??????????????????????????????????????????
function TANGER_OCX_SetMarkModify(boolvalue)
{
	TANGER_OCX_SetReviewMode(boolvalue);
	TANGER_OCX_EnableReviewBar(!boolvalue);
}

//????/??????????????
function TANGER_OCX_ShowRevisions(boolvalue)
{
	TANGER_OCX_OBJ.ActiveDocument.ShowRevisions = boolvalue;
}

//????/??????????????
function TANGER_OCX_PrintRevisions(boolvalue)
{
	TANGER_OCX_OBJ.ActiveDocument.PrintRevisions = boolvalue;
}

function TANGER_OCX_SaveToServer()
{
	if(!TANGER_OCX_bDocOpen)
	{
		alert("????????????????");
		return;
	}
	
	TANGER_OCX_filename = prompt("????????????","??????.doc");
	if ( (!TANGER_OCX_filename))
	{
		TANGER_OCX_filename ="";
		return;
	}
	else if (strtrim(TANGER_OCX_filename)=="")
	{
		alert("??????????????????");
		return;
	}
	//alert(TANGER_OCX_filename);
	TANGER_OCX_SaveDoc();
}


//????????????
function TANGER_OCX_ChgLayout()
{
 	try
	{
		TANGER_OCX_OBJ.showdialog(5); //????????????
	}
	catch(err){
		alert("??????" + err.number + ":" + err.description);
	}
	finally{
	}
}

//????????
function TANGER_OCX_PrintDoc()
{
	try
	{
		TANGER_OCX_OBJ.printout(true);
	}
	catch(err){
		alert("??????" + err.number + ":" + err.description);
	}
	finally{
	}
}

function TANGER_OCX_SaveEditToServer()
{
	if(!TANGER_OCX_bDocOpen)
	{
		alert("????????????????");
		return;
	}
	
	TANGER_OCX_filename = document.all.item("filename").value;
	if ( (!TANGER_OCX_filename))
	{
		TANGER_OCX_filename ="";
		return;
	}
	else if (strtrim(TANGER_OCX_filename)=="")
	{
		alert("??????????????????");
		return;
	}
	//alert(TANGER_OCX_filename);
	TANGER_OCX_SaveDoc();
}

//????????????????>????????
function TANGER_OCX_EnableFileNewMenu(boolvalue)
{
	TANGER_OCX_OBJ.EnableFileCommand(0) = boolvalue;
}
//????????????????>????????
function TANGER_OCX_EnableFileOpenMenu(boolvalue)
{
	TANGER_OCX_OBJ.EnableFileCommand(1) = boolvalue;
}
//????????????????>????????
function TANGER_OCX_EnableFileCloseMenu(boolvalue)
{
	TANGER_OCX_OBJ.EnableFileCommand(2) = boolvalue;
}
//????????????????>????????
function TANGER_OCX_EnableFileSaveMenu(boolvalue)
{
	TANGER_OCX_OBJ.EnableFileCommand(3) = boolvalue;
}
//????????????????>??????????
function TANGER_OCX_EnableFileSaveAsMenu(boolvalue)
{
	TANGER_OCX_OBJ.EnableFileCommand(4) = boolvalue;
}
//????????????????>????????
function TANGER_OCX_EnableFilePrintMenu(boolvalue)
{
	TANGER_OCX_OBJ.EnableFileCommand(5) = boolvalue;
}
//????????????????>????????????
function TANGER_OCX_EnableFilePrintPreviewMenu(boolvalue)
{
	TANGER_OCX_OBJ.EnableFileCommand(6) = boolvalue;
}

function TANGER_OCX_OpenDoc(docid)
{
	TANGER_OCX_OBJ = document.all.item("TANGER_OCX");
	if(docid != "")
	{	
		TANGER_OCX_OBJ.BeginOpenFromURL("readdoc.jsp?docid=" + docid);
	}
	else
	{
		TANGER_OCX_OBJ.CreateNew("Word.Document");
	}
}

function TANGER_OCX_OnDocumentOpened(str, obj)
{
	TANGER_OCX_bDocOpen = true;		
	TANGER_OCX_SetMarkModify(true);
	
}

function TANGER_OCX_OnDocumentClosed()
{
   TANGER_OCX_bDocOpen = false;
}

function TANGER_OCX_SaveDoc()
{
	var newwin,newdoc;

	if(!TANGER_OCX_bDocOpen)
	{
		alert("????????????????");
		return;
	}

	try
	{
	 	if(!TANGER_OCX_doFormOnSubmit())return; //??????????????????????onsubmit??????
	 	//??????????SaveToURL????
		var retHTML = TANGER_OCX_OBJ.SaveToURL
		(
			document.forms[0].action,  //??????uploadedit.asp
			"EDITFILE",	//??????????????,??????,????????<input type=file name=..>??name????????????
			"", //??????????????????????????????&??????????myname=tanger&hisname=tom,????????
			document.forms[0].filename.value, //??????,??????????????????????????????
			"myForm" //??????????????????????????????????????????????????????.??????????id????????
		); //??????????????????????????????????????????????????
		//??????????????????????????
		newwin = window.open("","_blank","left=200,top=200,width=400,height=300,status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1",false);
		newdoc = newwin.document;
		newdoc.open();
		newdoc.write("<html><head><title>??????????</title></head><body><center><hr>")
		newdoc.write(retHTML+"<hr>");
		newdoc.write("<input type=button VALUE='????????' onclick='window.close()'>");
		newdoc.write('</center></body></html>');
		newdoc.close();
		if(window.opener) //??????????????????????????????????
		{
			window.opener.location.reload();
		}
		if(0 == TANGER_OCX_OBJ.StatusCode)window.close();
	}
	catch(err){
		alert("??????????URL??" + err.number + ":" + err.description);
	}
	finally{
	}
}
function TANGER_OCX_SaveAsHTML()
{
	var newwin,newdoc;

	if(!TANGER_OCX_bDocOpen)
	{
		alert("????????????????");
		return;
	}
	try
	{
		//??????????PublishAsHTMLToURL????
		var retHTML = TANGER_OCX_OBJ.PublishAsHTMLToURL
			(
				"uploadhtmls.jsp",
				"HTMLFILES", //??????????????,??????,????????????????????????
				"",
				document.forms[0].htmlfile.value
				//????????????5????????HTML FORM??????????id.????,????????????????
				//????????????html??????????????
			);
		newwin = window.open("","_blank","left=200,top=200,width=400,height=300,status=0,toolbar=0,menubar=0,location=0,scrollbars=1,resizable=1",false);
		newdoc = newwin.document;
		newdoc.open();
		newdoc.write("<center><hr>"+retHTML+"<hr><input type=button VALUE='????????' onclick='window.close()'></center>");
		newdoc.close();	
		newwin.focus();
		if(window.opener) //??????????????????????????????????
		{
			window.opener.location.reload();
		}
	}
	catch(err){
		alert("??????????URL??" + err.number + ":" + err.description);
	}
	finally{
	}
}